﻿using StudentManagement.BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace StudentManagement
{
    /// <summary>
    /// Login.xaml 的交互逻辑
    /// </summary>
    public partial class Login : Window
    {
        public Login()
        {
            InitializeComponent();
        }
        MainWindow mainWindow = new MainWindow();
        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            //this.Close();
            Environment.Exit(0);
        }

        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            string name = txtLonginID.Text.Trim();
            string pwd = txtPassword.Password;
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(pwd))
            {
                MessageBox.Show("账号或者密码不能为空！");
                this.txtLonginID.Focus();
                return;
            }
            LoginBussiness loginBussiness = new LoginBussiness();
            bool flag = loginBussiness.CheckLogin(name, pwd);
            if (flag)
            {
                this.Close();
                mainWindow.UseName.Content = name;
                mainWindow.UseAccount.Content = name;
                mainWindow.Show();
            }
            else
            {
                MessageBox.Show("帐号或密码错误！");
            }
        }
    }
}
